﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Configuration;
using System.Data.SqlClient;
using System.Data;

namespace OnlineRailway.UI.Client
{
    public partial class TrainDetails : System.Web.UI.Page
    {
        SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["RailwayOnlineConnectionString"].ToString());
        private SqlDataAdapter dap;
        private SqlCommand comm;
        protected void Page_Load(object sender, EventArgs e)
        {
               comm = con.CreateCommand();
               comm.CommandText = "Select TrainNo,TrainName,StartStation,Departure,EndStation,Arrival,d.DayID,d.ScheduleID from dbo.DayMasters d,Trains t,TrainSchedules s where d.TrainID=t.TrainID and d.ScheduleID=s.ScheduleID and departure >= @date and s.StartStation=@start and s.EndStation=@end";
                comm.Parameters.AddWithValue("@start", Session["source"].ToString());
                comm.Parameters.AddWithValue("@end", Session["destination"].ToString());
                comm.Parameters.AddWithValue("@date", Session["date"].ToString());
                dap = new SqlDataAdapter(comm);
                con.Open();
                DataSet ds = new DataSet();
                //DataTable dt = new DataTable();
                dap.Fill(ds);
                GridView1.DataSource = ds;
                GridView1.DataBind();
                con.Close();

            lblSource.Text = Session["source"].ToString();
            lblDestination.Text = Session["destination"].ToString();
            lblDate.Text = Session["date"].ToString();
        }
    }
}